package com.offcn.controller;

import com.offcn.bean.Employee;
import com.offcn.service.EmployeeServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController// springmvc的注解, 表示这是一个控制器, 所有的响应都是以json数据格式响应
@RequestMapping("emp")//资源定位
public class EmployeeController {
    @Autowired
   private EmployeeServcie employeeServcie;

    @GetMapping //访问localhost:8080/emp
    public List<Employee> findAll(){
        return employeeServcie.findAll();
    }

    @GetMapping("{id}") //访问localhost:8080/emp/1
    public Employee findById(@PathVariable int id){
        return employeeServcie.findById(id);
    }

}
